import { ss } from '@/utils/storage'

const LOCAL_NAME = 'settingsStorage'

export interface SettingsState {
	superAdmin: boolean,
  systemMessage: string
  temperature: number
  top_p: number,
	kg: boolean,
	kgName: string,
	answer: string
}

export function defaultSetting(): SettingsState {
  return {
  	superAdmin: false,
    systemMessage: 'You are Xbrain Chat Bot, a large language model trained by Intellicloud. Follow the user\'s instructions carefully. Respond using markdown.',
    temperature: 0.8,
    top_p: 1,
		kg: false,
		kgName: '',
		answer: '对不起，我不知道，请添加相关内容到数据库中。'
  }
}

export function getLocalState(): SettingsState {
  const localSetting: SettingsState | undefined = ss.get(LOCAL_NAME)
  return { ...defaultSetting(), ...localSetting }
}

export function setLocalState(setting: SettingsState): void {
  ss.set(LOCAL_NAME, setting)
}

export function removeLocalState() {
  ss.remove(LOCAL_NAME)
}
